package cn.edu.scau.cmi.pengyujin.composite.consistent;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Organization extends ConsistentComponent{

	String name;
	List<Person> personList = new ArrayList<Person>();
	List<Team> teamList = new ArrayList<Team>();
	
	public void addPerson(Person person) {
		this.personList.add(person);
	}
	
	public void removePerson(Person person) {
		this.personList.remove(person);
	}
	
	public void addTeam(Team team) {
		this.teamList.add(team);
	}
	
	public void removePerson(Team team) {
		this.teamList.remove(team);
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<Person> getPersonList() {
		return personList;
	}

	public void setPersonList(List<Person> personList) {
		this.personList = personList;
	}

	public List<Team> getTeamList() {
		return teamList;
	}

	public void setTeamList(List<Team> teamList) {
		this.teamList = teamList;
	}

	@Override
	public void doSomething() {
		// TODO Auto-generated method stub
		System.out.println("我是组织："+this.name);
	}
	
	@Override
	public void getParent() {
		// TODO Auto-generated method stub
		//迭代输出父节点，personList
		this.doSomething();
		Iterator<Person> iterator1 = personList.iterator();
		Iterator<Team> iterator2 = teamList.iterator();
		Person person = null;
		Team team = null;
		while(iterator2.hasNext()) {
			team = iterator2.next();
			team.doSomething();
			Iterator<Person> iterator3 = team.getPersonList().iterator();
			System.out.println("{");
			while(iterator3.hasNext()) {
				person = iterator3.next();
				person.doSomething();
			}
			System.out.println("}");
			
		}
		while(iterator1.hasNext()) {
			person = iterator1.next();
			person.doSomething();
		}
	}
	

	

}
